layui.use(['form','upload', 'element', 'layer'], function(){
    var form = layui.form
        ,$ = layui.jquery
        ,upload = layui.upload
        ,element = layui.element
        ,layer = layui.layer;;
    $('#button_refresh').click(function(){
        location.reload();
    });
    $('#button_return').click(function(){
        window.location.href = document.referrer;
    });
    var uploadInst = upload.render({
        elem: '#test1'
        ,url: '/uploadCourse/uploadImg' //改成您自己的上传接口
        ,before: function(obj){
            //预读本地文件示例，不支持ie8
            obj.preview(function(index, file, result){
                $('#demo1').attr('src', result); //图片链接（base64）
            });
            element.progress('demo', '0%'); //进度条复位
            layer.msg('上传成功');
        }
        ,done: function(res){
            //如果上传失败
            if(res.code > 0){
                return layer.msg('上传失败');
            }
            //上传成功的一些操作
            //……
            $('#demoText').html(''); //置空上传失败的状态
        }
        ,error: function(){
            //演示失败状态，并实现重传
            var demoText = $('#demoText');
            demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
            demoText.find('.demo-reload').on('click', function(){
                uploadInst.upload();
            });
        }
    });
    (function() {$('#file').on('change', function() {
        var files = this.files,
            video = $('#video').find('video'),
            videoURL = null,
            windowURL = window.URL || window.webkitURL;;
        if(files && files[0]) {
            videoURL = windowURL.createObjectURL(files[0]);
            $('#video video').attr('src', videoURL);
            $('#video video').trigger('click');
        }
    }).trigger('change');
    })();


});
//添加课程分类
function addCourse() {
    layer.open({
        type:2,
        title:"添加课程分类",
        area:['600px', '500px'],
        offset:'auto',
        shade:0.5,
        maxmin:true,
        content:"AddCourseCategory.html",
        success:function(layero,index){
            $("#p_id").attr("style","display:block");
        }
    })
    window.layer_1=layer;
}
//添加课程

